﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace Gollie.Pdf
{
	public class PdfTable : PdfPTable
	{
		internal PdfElementProperties Properties;
		Font headerFont;
		Font cellFont;

		public PdfTable(PdfElementProperties properties)
			: base(properties.TableHeaders == null ? 1 : properties.TableHeaders.Length)
		{
			this.Properties = properties;

			this.ColumnCount = properties.TableHeaders == null ? 1 : properties.TableHeaders.Length;

			if (properties.CellWidths != null)
				this.SetWidths(properties.CellWidths);

			this.TotalWidth = properties.TableWidth;

			headerFont = FontFactory.GetFont(properties.FontFamily, properties.FontSize, Font.BOLD);
			cellFont = FontFactory.GetFont(properties.FontFamily, properties.FontSize, properties.FontWeight);
		}

		public PdfRow NewRow()
		{
			PdfRow row = new PdfRow(this.ColumnCount);

			return row;
		}

		public PdfRow NewRow(PdfCellProperties cellProperties)
		{
			PdfRow row = new PdfRow(cellProperties, this.ColumnCount);

			return row;
		}

		public PdfRow NewRow(PdfCellProperties cellProperties, string[] texts)
		{
			PdfRow row = new PdfRow(cellProperties, texts, this.ColumnCount);

			return row;
		}

		public PdfRow NewRow(PdfCellProperties[] cellProperties, string[] texts)
		{
			PdfRow row = new PdfRow(cellProperties, texts, this.ColumnCount);

			return row;
		}

		public void AddRow()
		{
			this.AddRow(this.NewRow());
		}

		public void AddRow(PdfCellProperties cellProperties)
		{
			this.AddRow(this.NewRow(cellProperties));
		}

		public void AddRow(PdfCellProperties cellProperties, string[] texts)
		{
			this.AddRow(this.NewRow(cellProperties, texts));
		}

		public void AddRow(PdfCellProperties[] cellProperties, string[] texts)
		{
			this.AddRow(this.NewRow(cellProperties, texts));
		}

		public void AddRow(PdfRow row)
		{
			foreach (PdfCell cell in row)
				this.AddCell(cell);
		}

		public int ColumnCount
		{
			get;
			private set;
		}
	}
}
